from lxml import etree
import urllib.request

url = "https://www.baidu.com"

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'
}

# 请求对象的定制
request = urllib.request.Request(url=url, headers=headers)
# 模拟浏览器访问服务器
response = urllib.request.urlopen(request)
# 获取网页源码
content = response.read().decode("utf-8")
# print(content)

tree = etree.HTML(content)

# 获取想要的数据 xpath返回的是一个列表类型的数据
result = tree.xpath("//input[@id='su']/@value")
print(tree)